<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>微信小程序支付、退款、转账 | Ahuang'Blog</title><meta name="author" content="Ahuang"><meta name="copyright" content="Ahuang"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="配置参数 1234567891011&#x2F;&#x2F;微信参数   &amp;#x27;app_id&amp;#x27; 		&#x3D;&gt; &amp;#x27;&amp;#x27;,   &amp;#x27;app_secret&amp;#x27; 	&#x3D;&gt; &amp;#x27;&amp;#x27;,   &#x2F;&#x2F;支付参数   &amp;#x27;mchid&amp;#x27;			&#x3D;&gt;	&amp;#x27;&amp;#x27;,   &amp;#x27;key&amp;#x27;			&#x3D;&gt;	&amp;#x27;&amp;#x">
<meta property="og:type" content="article">
<meta property="og:title" content="微信小程序支付、退款、转账">
<meta property="og:url" content="http://huangxiaochang.gitee.io/ahuang_blog/2020/05/05/015/index.html">
<meta property="og:site_name" content="Ahuang&#39;Blog">
<meta property="og:description" content="配置参数 1234567891011&#x2F;&#x2F;微信参数   &amp;#x27;app_id&amp;#x27; 		&#x3D;&gt; &amp;#x27;&amp;#x27;,   &amp;#x27;app_secret&amp;#x27; 	&#x3D;&gt; &amp;#x27;&amp;#x27;,   &#x2F;&#x2F;支付参数   &amp;#x27;mchid&amp;#x27;			&#x3D;&gt;	&amp;#x27;&amp;#x27;,   &amp;#x27;key&amp;#x27;			&#x3D;&gt;	&amp;#x27;&amp;#x">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png">
<meta property="article:published_time" content="2020-05-05T09:50:01.000Z">
<meta property="article:modified_time" content="2023-01-31T12:21:54.715Z">
<meta property="article:author" content="Ahuang">
<meta property="article:tag" content="微信支付">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png"><link rel="shortcut icon" href="/ahuang_blog/img/favicon.ico"><link rel="canonical" href="http://huangxiaochang.gitee.io/ahuang_blog/2020/05/05/015/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><link rel="stylesheet" href="/ahuang_blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/ahuang_blog/',
  algolia: undefined,
  localSearch: {"path":"/ahuang_blog/search.xml","preload":true,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: {"limitDay":500,"position":"top","messagePrev":"It has been","messageNext":"days since the last update, the content of the article may be outdated."},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":400},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '微信小程序支付、退款、转账',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2023-01-31 20:21:54'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = url => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      link.onload = () => resolve()
      link.onerror = () => reject()
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/blog/css/transpancy.css"><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/js-heo@1.0.11/mainColor/heoMainColor.css"><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/js-heo@1.0.11/categoryBar/categoryBar.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.css" /><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/ahuang_blog/img/Misaka.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/ahuang_blog/archives/"><div class="headline">文章</div><div class="length-num">51</div></a><a href="/ahuang_blog/tags/"><div class="headline">标签</div><div class="length-num">35</div></a><a href="/ahuang_blog/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/ahuang_blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image: url('https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png')"><nav id="nav"><span id="blog-info"><a href="/ahuang_blog/" title="Ahuang'Blog"><span class="site-name">Ahuang'Blog</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/ahuang_blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">微信小程序支付、退款、转账</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-05-05T09:50:01.000Z" title="发表于 2020-05-05 17:50:01">2020-05-05</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-01-31T12:21:54.715Z" title="更新于 2023-01-31 20:21:54">2023-01-31</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/ahuang_blog/categories/PHP/">PHP</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.5k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>12分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="微信小程序支付、退款、转账"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>配置参数</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">//微信参数</span><br><span class="line">   <span class="string">&#x27;app_id&#x27;</span> 		=&gt; <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">   <span class="string">&#x27;app_secret&#x27;</span> 	=&gt; <span class="string">&#x27;&#x27;</span>,</span><br><span class="line"></span><br><span class="line">   //支付参数</span><br><span class="line">   <span class="string">&#x27;mchid&#x27;</span>			=&gt;	<span class="string">&#x27;&#x27;</span>,</span><br><span class="line">   <span class="string">&#x27;key&#x27;</span>			=&gt;	<span class="string">&#x27;&#x27;</span>,</span><br><span class="line">   <span class="string">&#x27;notify_url&#x27;</span>	=&gt;	<span class="string">&quot;/api/v1/wechatpay/notify_url&quot;</span>,</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>下单支付生成签名 （调用支付业务类）</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">(new \tool\Pay())-&gt;getWechatPaySign(<span class="variable">$openid</span>,  <span class="variable">$price</span>, <span class="variable">$order_no</span>, <span class="string">&#x27;商品名&#x27;</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<p>支付成功回调  （调用支付业务类）</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">(new \tool\Pay())-&gt;getWechatPaySign(<span class="variable">$openid</span>,  <span class="variable">$price</span>, <span class="variable">$order_no</span>, <span class="string">&#x27;商品名&#x27;</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<p>退款  （调用支付业务类）</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> *  退款</span><br><span class="line"> * @param <span class="built_in">float</span> <span class="variable">$totalFee</span> 订单金额 单位元</span><br><span class="line"> * @param <span class="built_in">float</span> <span class="variable">$refundFee</span> 退款金额 单位元</span><br><span class="line"> * @param string <span class="variable">$refundNo</span> 退款单号</span><br><span class="line"> * @param string <span class="variable">$orderNo</span> 商户订单号</span><br><span class="line"> */</span><br><span class="line">(new \tool\Pay())-&gt;refund(<span class="variable">$totalFee</span>, <span class="variable">$refundFee</span>, <span class="variable">$orderNo</span>, <span class="variable">$refundNo</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<p>转账 （商户号需要一段时间保持每天都有流水才能成功）</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> *  转账</span><br><span class="line"> * @param <span class="built_in">float</span> <span class="variable">$openid</span> 用户的openid</span><br><span class="line"> * @param <span class="built_in">float</span> <span class="variable">$transferFee</span> 转账金额 单位元</span><br><span class="line"> * @param string <span class="variable">$trade_no</span> 商户订单号</span><br><span class="line"> */</span><br><span class="line">(new \tool\Pay())-&gt;transfer(<span class="variable">$openid</span>, <span class="variable">$trade_no</span>, <span class="variable">$transferFee</span>)</span><br></pre></td></tr></table></figure>



<p>支付业务类  （调用支付工具类）</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line"></span><br><span class="line">namespace tool;</span><br><span class="line">use  wechat\WechatPay;</span><br><span class="line"></span><br><span class="line">class Pay</span><br><span class="line">&#123;</span><br><span class="line">    protected <span class="variable">$app_id</span>;</span><br><span class="line">    protected <span class="variable">$key</span>;</span><br><span class="line">    protected <span class="variable">$mchid</span>;</span><br><span class="line">    protected <span class="variable">$notify_url</span>;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * Pay constructor.</span><br><span class="line">     * @param <span class="variable">$openid</span>  //openid</span><br><span class="line">     * @param <span class="variable">$total_fee</span>  //支付金额</span><br><span class="line">     * @param <span class="variable">$out_trade_no</span>  //单号</span><br><span class="line">     * @param <span class="variable">$body</span>  //商品说明</span><br><span class="line">     */</span><br><span class="line">    public <span class="keyword">function</span> <span class="function"><span class="title">__construct</span></span>()</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$this</span>-&gt;app_id = config(<span class="string">&#x27;wxapp.app_id&#x27;</span>);</span><br><span class="line">        <span class="variable">$this</span>-&gt;key = config(<span class="string">&#x27;wxapp.key&#x27;</span>);</span><br><span class="line">        <span class="variable">$this</span>-&gt;mchid = config(<span class="string">&#x27;wxapp.mchid&#x27;</span>);</span><br><span class="line">        <span class="variable">$this</span>-&gt;notify_url = config(<span class="string">&#x27;wxapp.notify_url&#x27;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 微信支付 获取签名</span><br><span class="line">     * @param <span class="variable">$openid</span></span><br><span class="line">     * @param <span class="variable">$total_fee</span>  //订单金额</span><br><span class="line">     * @param <span class="variable">$out_trade_no</span>  //订单号</span><br><span class="line">     * @param <span class="variable">$body</span>      //描述</span><br><span class="line">     * @<span class="built_in">return</span> array</span><br><span class="line">     */</span><br><span class="line">    public <span class="keyword">function</span>  getWechatPaySign(<span class="variable">$openid</span>,<span class="variable">$total_fee</span>, <span class="variable">$out_trade_no</span>, <span class="variable">$body</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$wechatPay</span> = new  WechatPay();</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setAppId(<span class="variable">$this</span>-&gt;app_id);</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setKey(<span class="variable">$this</span>-&gt;key);</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setMchid(<span class="variable">$this</span>-&gt;mchid);</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setNotifyUrl(<span class="variable">$this</span>-&gt;notify_url);</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setOpenid(<span class="variable">$openid</span>);</span><br><span class="line">        //</span><br><span class="line">        <span class="variable">$data</span>=  <span class="variable">$wechatPay</span>-&gt;getSignParameters(<span class="variable">$out_trade_no</span>,<span class="variable">$total_fee</span>,  <span class="variable">$body</span>);</span><br><span class="line">        <span class="built_in">return</span> <span class="variable">$data</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     *  退款</span><br><span class="line">     * @param <span class="built_in">float</span> <span class="variable">$totalFee</span> 订单金额 单位元</span><br><span class="line">     * @param <span class="built_in">float</span> <span class="variable">$refundFee</span> 退款金额 单位元</span><br><span class="line">     * @param string <span class="variable">$refundNo</span> 退款单号</span><br><span class="line">     * @param string <span class="variable">$orderNo</span> 商户订单号</span><br><span class="line">     */</span><br><span class="line">    public  <span class="keyword">function</span>  refund(<span class="variable">$totalFee</span>, <span class="variable">$refundFee</span>, <span class="variable">$orderNo</span>, <span class="variable">$refundNo</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$wechatPay</span> = new  WechatPay();</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setAppId(<span class="variable">$this</span>-&gt;app_id);</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setKey(<span class="variable">$this</span>-&gt;key);</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setMchid(<span class="variable">$this</span>-&gt;mchid);</span><br><span class="line">        <span class="variable">$data</span>=  <span class="variable">$wechatPay</span>-&gt;doRefund(<span class="variable">$totalFee</span>, <span class="variable">$refundFee</span>, <span class="variable">$orderNo</span>, <span class="variable">$refundNo</span>);</span><br><span class="line">        <span class="built_in">return</span> <span class="variable">$data</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 转账</span><br><span class="line">     * @param <span class="built_in">float</span> <span class="variable">$transferFee</span> 转账金额 单位元</span><br><span class="line">     * @param string <span class="variable">$trade_no</span> 商户订单号</span><br><span class="line">     * @<span class="built_in">return</span> string</span><br><span class="line">     */</span><br><span class="line">    public <span class="keyword">function</span>  transfer(<span class="variable">$openid</span>, <span class="variable">$trade_no</span>, <span class="variable">$transferFee</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$wechatPay</span> = new  WechatPay();</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setAppId(<span class="variable">$this</span>-&gt;app_id);</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setKey(<span class="variable">$this</span>-&gt;key);</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setMchid(<span class="variable">$this</span>-&gt;mchid);</span><br><span class="line">        <span class="variable">$wechatPay</span>-&gt;setOpenid(<span class="variable">$openid</span>);</span><br><span class="line">        <span class="variable">$data</span>=  <span class="variable">$wechatPay</span>-&gt;transfer(<span class="variable">$trade_no</span>,<span class="variable">$transferFee</span>);</span><br><span class="line">        <span class="built_in">return</span> <span class="variable">$data</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>




<p>封装的支付工具类</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line">namespace  wechat;</span><br><span class="line"></span><br><span class="line">class WechatPay</span><br><span class="line">&#123;</span><br><span class="line">    const WECHAT_URL = <span class="string">&#x27;https://api.mch.weixin.qq.com&#x27;</span>;</span><br><span class="line">    const UNIFIEDORDER = <span class="string">&#x27;/pay/unifiedorder&#x27;</span>;</span><br><span class="line">    const REFUND = <span class="string">&#x27;/secapi/pay/refund&#x27;</span>;</span><br><span class="line">    const TRANSFERS = <span class="string">&#x27;/mmpaymkttransfers/promotion/transfers&#x27;</span>;</span><br><span class="line">    //证书路径</span><br><span class="line">    public <span class="variable">$SSLCERT_PATH</span> = <span class="string">&quot;/www/wwwroot/kids/public/cert/apiclient_cert.pem&quot;</span>;</span><br><span class="line">    public <span class="variable">$SSLKEY_PATH</span> = <span class="string">&quot;/www/wwwroot/kids/public/cert/apiclient_key.pem&quot;</span>;</span><br><span class="line">    //</span><br><span class="line">    protected <span class="variable">$app_id</span>;</span><br><span class="line">    protected <span class="variable">$key</span>;</span><br><span class="line">    protected <span class="variable">$mchid</span>;</span><br><span class="line">    protected <span class="variable">$notify_url</span>;</span><br><span class="line">    protected <span class="variable">$openid</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 微信支付</span><br><span class="line">     * 所用到的请求参数</span><br><span class="line">     * @param <span class="variable">$out_trade_no</span>   //订单号</span><br><span class="line">     * @param <span class="variable">$total_fee</span>    //支付金额</span><br><span class="line">     * @param <span class="variable">$body</span>    //订单描述</span><br><span class="line">     * @<span class="built_in">return</span> array jssdk需要用到的数据</span><br><span class="line">     */</span><br><span class="line">    public <span class="keyword">function</span> getSignParameters(<span class="variable">$out_trade_no</span>, <span class="variable">$total_fee</span>, <span class="variable">$body</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        header(<span class="string">&quot;Content-type:text/html;charset=utf-8&quot;</span>);</span><br><span class="line">        //</span><br><span class="line">        <span class="variable">$parameters</span>=array(</span><br><span class="line">            <span class="string">&#x27;body&#x27;</span>          =&gt;  <span class="variable">$body</span>,</span><br><span class="line">            <span class="string">&#x27;total_fee&#x27;</span>     =&gt;  <span class="variable">$total_fee</span> * 100,</span><br><span class="line">            <span class="string">&#x27;out_trade_no&#x27;</span>  =&gt;  <span class="variable">$out_trade_no</span>,</span><br><span class="line">            <span class="string">&#x27;trade_type&#x27;</span>    =&gt;  <span class="string">&#x27;JSAPI&#x27;</span>,      // JSAPI公众号/小程序支付</span><br><span class="line">            <span class="string">&#x27;openid&#x27;</span>        =&gt;  <span class="variable">$this</span>-&gt;openid,</span><br><span class="line">        );</span><br><span class="line">        // 统一下单 获取prepay_id</span><br><span class="line">        <span class="variable">$unified_order</span>=<span class="variable">$this</span>-&gt;unifiedOrder(<span class="variable">$parameters</span>);</span><br><span class="line">        // 获取当前时间戳</span><br><span class="line">        <span class="variable">$time</span>=time();</span><br><span class="line">        // 组合jssdk需要用到的数据</span><br><span class="line">        <span class="variable">$data</span>=array(</span><br><span class="line">            <span class="string">&#x27;appId&#x27;</span>     =&gt;<span class="variable">$this</span>-&gt;app_id, //appid</span><br><span class="line">            <span class="string">&#x27;timeStamp&#x27;</span> =&gt;strval(<span class="variable">$time</span>), //时间戳</span><br><span class="line">            <span class="string">&#x27;nonceStr&#x27;</span>  =&gt;<span class="variable">$unified_order</span>[<span class="string">&#x27;nonce_str&#x27;</span>],// 随机字符串</span><br><span class="line">            <span class="string">&#x27;package&#x27;</span>   =&gt;<span class="string">&#x27;prepay_id=&#x27;</span>.<span class="variable">$unified_order</span>[<span class="string">&#x27;prepay_id&#x27;</span>],// 预支付交易会话标识</span><br><span class="line">            <span class="string">&#x27;signType&#x27;</span>  =&gt;<span class="string">&#x27;MD5&#x27;</span>//加密方式</span><br><span class="line">        );</span><br><span class="line">        // 生成签名</span><br><span class="line">        <span class="variable">$data</span>[<span class="string">&#x27;paySign&#x27;</span>]=<span class="variable">$this</span>-&gt;makeSign(<span class="variable">$data</span>);</span><br><span class="line">        <span class="built_in">return</span> <span class="variable">$data</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 微信退款</span><br><span class="line">     * @param <span class="built_in">float</span> <span class="variable">$totalFee</span> 订单金额 单位元</span><br><span class="line">     * @param <span class="built_in">float</span> <span class="variable">$refundFee</span> 退款金额 单位元</span><br><span class="line">     * @param string <span class="variable">$refundNo</span> 退款单号</span><br><span class="line">     * @param string <span class="variable">$orderNo</span> 商户订单号</span><br><span class="line">     * @<span class="built_in">return</span> string</span><br><span class="line">     */</span><br><span class="line">    public <span class="keyword">function</span> doRefund(<span class="variable">$totalFee</span>, <span class="variable">$refundFee</span>, <span class="variable">$orderNo</span>, <span class="variable">$refundNo</span>)</span><br><span class="line">    &#123;</span><br><span class="line"></span><br><span class="line">        <span class="variable">$unified</span> = array(</span><br><span class="line">            <span class="string">&#x27;appid&#x27;</span>         =&gt;    <span class="variable">$this</span>-&gt;app_id,</span><br><span class="line">            <span class="string">&#x27;mch_id&#x27;</span>        =&gt;    <span class="variable">$this</span>-&gt;mchid,</span><br><span class="line">            <span class="string">&#x27;nonce_str&#x27;</span>     =&gt;    <span class="variable">$this</span>-&gt;getNonceStr(),</span><br><span class="line">            <span class="string">&#x27;total_fee&#x27;</span>     =&gt;    intval(<span class="variable">$totalFee</span> * 100),    //订单金额  单位 转为分</span><br><span class="line">            <span class="string">&#x27;refund_fee&#x27;</span>    =&gt;    intval(<span class="variable">$refundFee</span> * 100),    //退款金额 单位 转为分</span><br><span class="line">            <span class="string">&#x27;sign_type&#x27;</span>     =&gt;    <span class="string">&#x27;MD5&#x27;</span>,      //签名类型 支持HMAC-SHA256和MD5，默认为MD5</span><br><span class="line">            <span class="string">&#x27;out_trade_no&#x27;</span>  =&gt;    <span class="variable">$orderNo</span>,    //商户订单号</span><br><span class="line">            <span class="string">&#x27;out_refund_no&#x27;</span> =&gt;    <span class="variable">$refundNo</span>,    //商户退款单号</span><br><span class="line">        );</span><br><span class="line">        <span class="variable">$unified</span>[<span class="string">&#x27;sign&#x27;</span>] = <span class="variable">$this</span>-&gt;makeSign(<span class="variable">$unified</span>);</span><br><span class="line">        <span class="variable">$url</span> = self::WECHAT_URL.self::REFUND;</span><br><span class="line">        <span class="variable">$mxl</span> = <span class="variable">$this</span>-&gt;toXml(<span class="variable">$unified</span>);</span><br><span class="line">        <span class="variable">$responseXml</span> =  <span class="variable">$this</span>-&gt;postXmlCurl( <span class="variable">$mxl</span>,<span class="variable">$url</span>, <span class="literal">true</span>);</span><br><span class="line">        <span class="variable">$unifiedOrder</span> = simplexml_load_string(<span class="variable">$responseXml</span>, <span class="string">&#x27;SimpleXMLElement&#x27;</span>, LIBXML_NOCDATA);</span><br><span class="line">        <span class="keyword">if</span> (<span class="variable">$unifiedOrder</span> === <span class="literal">false</span>) &#123;</span><br><span class="line">            throw new \Exception(<span class="string">&#x27;parse xml error&#x27;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (<span class="variable">$unifiedOrder</span>-&gt;return_code != <span class="string">&#x27;SUCCESS&#x27;</span>) &#123;</span><br><span class="line">            throw new \Exception(<span class="variable">$unifiedOrder</span>-&gt;return_msg);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (<span class="variable">$unifiedOrder</span>-&gt;result_code != <span class="string">&#x27;SUCCESS&#x27;</span>) &#123;</span><br><span class="line">            throw new \Exception(<span class="variable">$unifiedOrder</span>-&gt;err_code);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 转账</span><br><span class="line">     * @param <span class="built_in">float</span> <span class="variable">$openid</span> 转账的openid</span><br><span class="line">     * @param <span class="built_in">float</span> <span class="variable">$transferFee</span> 转账金额 单位元</span><br><span class="line">     * @param string <span class="variable">$check_name</span>  OPTION_CHECK不强制校验真实姓名, FORCE_CHECK：强制 NO_CHECK：</span><br><span class="line">     * @param string <span class="variable">$desc</span> 企业付款描述信息</span><br><span class="line">     * @param string <span class="variable">$trade_no</span> 商户订单号</span><br><span class="line">     * @<span class="built_in">return</span> string</span><br><span class="line">     */</span><br><span class="line">    public <span class="keyword">function</span> transfer(<span class="variable">$trade_no</span>,<span class="variable">$transferFee</span>,<span class="variable">$check_name</span>=<span class="string">&quot;NO_CHECK&quot;</span>,<span class="variable">$desc</span>=<span class="string">&quot;分账提现&quot;</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$param</span>   = array(</span><br><span class="line">            <span class="string">&#x27;mch_appid&#x27;</span>         =&gt;      <span class="variable">$this</span>-&gt;app_id,</span><br><span class="line">            <span class="string">&#x27;mchid&#x27;</span>             =&gt;      <span class="variable">$this</span>-&gt;mchid,</span><br><span class="line">            <span class="string">&#x27;nonce_str&#x27;</span>         =&gt;      <span class="variable">$this</span>-&gt;getNonceStr(),</span><br><span class="line">            <span class="string">&#x27;amount&#x27;</span>            =&gt;      intval(<span class="variable">$transferFee</span> * 100),    //订单金额  单位 转为分</span><br><span class="line">            <span class="string">&#x27;partner_trade_no&#x27;</span>  =&gt;      <span class="variable">$trade_no</span>,    //商户订单号</span><br><span class="line">            <span class="string">&#x27;openid&#x27;</span>            =&gt;      <span class="variable">$this</span>-&gt;openid,</span><br><span class="line">            <span class="string">&#x27;check_name&#x27;</span>        =&gt;      <span class="variable">$check_name</span>, //OPTION_CHECK不强制校验真实姓名, FORCE_CHECK：强制 NO_CHECK：</span><br><span class="line">            <span class="string">&#x27;desc&#x27;</span>              =&gt;      <span class="variable">$desc</span>,//企业付款描述信息</span><br><span class="line">            <span class="string">&#x27;spbill_create_ip&#x27;</span>  =&gt;      <span class="variable">$_SERVER</span>[<span class="string">&#x27;REMOTE_ADDR&#x27;</span>],//获取IP</span><br><span class="line">        );</span><br><span class="line">        <span class="variable">$param</span>[<span class="string">&#x27;sign&#x27;</span>] = <span class="variable">$this</span>-&gt;makeSign(<span class="variable">$param</span>);</span><br><span class="line">        <span class="variable">$url</span> = self::WECHAT_URL.self::TRANSFERS;</span><br><span class="line">        <span class="variable">$xml</span> = <span class="variable">$this</span>-&gt;toXml(<span class="variable">$param</span>);</span><br><span class="line">        <span class="variable">$responseXml</span> = <span class="variable">$this</span>-&gt;postXmlCurl(<span class="variable">$xml</span>,<span class="variable">$url</span>,  <span class="literal">true</span>);</span><br><span class="line">        <span class="variable">$unifiedOrder</span> = simplexml_load_string(<span class="variable">$responseXml</span>, <span class="string">&#x27;SimpleXMLElement&#x27;</span>, LIBXML_NOCDATA);</span><br><span class="line">        <span class="keyword">if</span> (<span class="variable">$unifiedOrder</span> === <span class="literal">false</span>) &#123;</span><br><span class="line">            throw new \Exception(<span class="string">&#x27;parse xml error&#x27;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (<span class="variable">$unifiedOrder</span>-&gt;return_code != <span class="string">&#x27;SUCCESS&#x27;</span>) &#123;</span><br><span class="line">            throw new \Exception(<span class="variable">$unifiedOrder</span>-&gt;return_msg);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (<span class="variable">$unifiedOrder</span>-&gt;result_code != <span class="string">&#x27;SUCCESS&#x27;</span>) &#123;</span><br><span class="line">            throw new \Exception(<span class="variable">$unifiedOrder</span>-&gt;err_code);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">	</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">     * 统一下单</span><br><span class="line">     * @param  array <span class="variable">$order</span> 订单 必须包含支付所需要的参数 body(产品描述)、total_fee(订单金额)、out_trade_no(订单号)、product_id(产品<span class="built_in">id</span>)、trade_type(类型：JSAPI，NATIVE，APP)</span><br><span class="line">     */</span><br><span class="line">    public  <span class="keyword">function</span> unifiedOrder(<span class="variable">$parameters</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        //</span><br><span class="line">        <span class="variable">$config</span>=array(</span><br><span class="line">            <span class="string">&#x27;appid&#x27;</span>             =&gt;<span class="variable">$this</span>-&gt;app_id,</span><br><span class="line">            <span class="string">&#x27;mch_id&#x27;</span>            =&gt;<span class="variable">$this</span>-&gt;mchid,</span><br><span class="line">            <span class="string">&#x27;nonce_str&#x27;</span>         =&gt;<span class="variable">$this</span>-&gt;getNonceStr(),</span><br><span class="line">            <span class="string">&#x27;spbill_create_ip&#x27;</span>  =&gt;<span class="variable">$_SERVER</span>[<span class="string">&#x27;REMOTE_ADDR&#x27;</span>],</span><br><span class="line">            <span class="string">&#x27;notify_url&#x27;</span>        =&gt;<span class="string">&#x27;https://&#x27;</span>.<span class="variable">$_SERVER</span>[<span class="string">&#x27;HTTP_HOST&#x27;</span>].<span class="variable">$this</span>-&gt;notify_url,</span><br><span class="line">            );</span><br><span class="line">        //var_dump(<span class="variable">$config</span>);die;</span><br><span class="line">        // 合并配置数据和订单数据</span><br><span class="line">        <span class="variable">$data</span>=array_merge(<span class="variable">$parameters</span>,<span class="variable">$config</span>);</span><br><span class="line">        //var_dump(<span class="variable">$data</span>);die;</span><br><span class="line">        // 生成签名</span><br><span class="line">        <span class="variable">$sign</span>=<span class="variable">$this</span>-&gt;makeSign(<span class="variable">$data</span>);</span><br><span class="line">        <span class="variable">$data</span>[<span class="string">&#x27;sign&#x27;</span>]=<span class="variable">$sign</span>;</span><br><span class="line">        <span class="variable">$xml</span> =<span class="variable">$this</span>-&gt;toXml(<span class="variable">$data</span>);</span><br><span class="line">        <span class="variable">$url</span> =  self::WECHAT_URL.self::UNIFIEDORDER;  //接收xml数据的文件</span><br><span class="line">        <span class="variable">$header</span>[] = <span class="string">&quot;Content-type: text/xml&quot;</span>;//定义content-type为xml,注意是数组</span><br><span class="line">        <span class="variable">$wxresult</span> = <span class="variable">$this</span>-&gt;postXmlCurl(<span class="variable">$xml</span>,<span class="variable">$url</span>);</span><br><span class="line">        //转换成数组</span><br><span class="line">        <span class="variable">$result</span>=<span class="variable">$this</span>-&gt;toArray(<span class="variable">$wxresult</span>);</span><br><span class="line">        <span class="built_in">return</span>  <span class="variable">$result</span>;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    //设置app_id</span><br><span class="line">    public <span class="keyword">function</span> setAppId(<span class="variable">$app_id</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$this</span>-&gt;app_id = <span class="variable">$app_id</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    //设置key</span><br><span class="line">    public <span class="keyword">function</span> setKey(<span class="variable">$key</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$this</span>-&gt;key = <span class="variable">$key</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    //设置mchid</span><br><span class="line">    public <span class="keyword">function</span> setMchid(<span class="variable">$mchid</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$this</span>-&gt;mchid = <span class="variable">$mchid</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    //设置notify_url</span><br><span class="line">    public <span class="keyword">function</span> setNotifyUrl(<span class="variable">$notify_url</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$this</span>-&gt;notify_url = <span class="variable">$notify_url</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    //设置openid</span><br><span class="line">    public <span class="keyword">function</span> setOpenid(<span class="variable">$openid</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$this</span>-&gt;openid = <span class="variable">$openid</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 生成签名</span><br><span class="line">     * @<span class="built_in">return</span> 签名，本函数不覆盖sign成员变量，如要设置签名需要调用SetSign方法赋值</span><br><span class="line">     */</span><br><span class="line">    public  <span class="keyword">function</span> makeSign(<span class="variable">$data</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        // 去空</span><br><span class="line">        <span class="variable">$data</span>=array_filter(<span class="variable">$data</span>);</span><br><span class="line">        //签名步骤一：按字典序排序参数</span><br><span class="line">        ksort(<span class="variable">$data</span>);</span><br><span class="line">        //将数组转成url形式</span><br><span class="line">        <span class="variable">$string_a</span>=http_build_query(<span class="variable">$data</span>);</span><br><span class="line">        <span class="variable">$string_a</span>=urldecode(<span class="variable">$string_a</span>);</span><br><span class="line">        <span class="variable">$string_sign_temp</span>=<span class="variable">$string_a</span>.<span class="string">&quot;&amp;key=&quot;</span>.<span class="variable">$this</span>-&gt;key;</span><br><span class="line">        <span class="variable">$sign</span> = md5(<span class="variable">$string_sign_temp</span>);</span><br><span class="line">        <span class="variable">$result</span>=strtoupper(<span class="variable">$sign</span>);</span><br><span class="line">        <span class="built_in">return</span> <span class="variable">$result</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 将xml转为array</span><br><span class="line">     * @param  string <span class="variable">$xml</span> xml字符串</span><br><span class="line">     * @<span class="built_in">return</span> array       转换得到的数组</span><br><span class="line">     */</span><br><span class="line">    public  <span class="keyword">function</span> toArray(<span class="variable">$xml</span>)&#123;   </span><br><span class="line">        //禁止引用外部xml实体</span><br><span class="line">        libxml_disable_entity_loader(<span class="literal">true</span>);</span><br><span class="line">        <span class="variable">$result</span>= json_decode(json_encode(simplexml_load_string(<span class="variable">$xml</span>, <span class="string">&#x27;SimpleXMLElement&#x27;</span>, LIBXML_NOCDATA)), <span class="literal">true</span>);        </span><br><span class="line">        <span class="built_in">return</span> <span class="variable">$result</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * </span><br><span class="line">     * 产生随机字符串，不长于32位</span><br><span class="line">     * @param int <span class="variable">$length</span></span><br><span class="line">     * @<span class="built_in">return</span> 产生的随机字符串</span><br><span class="line">     */</span><br><span class="line">    public  <span class="keyword">function</span> getNonceStr(<span class="variable">$length</span> = 32) </span><br><span class="line">    &#123;</span><br><span class="line">        <span class="variable">$chars</span> = <span class="string">&quot;abcdefghijklmnopqrstuvwxyz0123456789&quot;</span>;  </span><br><span class="line">        <span class="variable">$str</span> =<span class="string">&quot;&quot;</span>;</span><br><span class="line">        <span class="keyword">for</span> ( <span class="variable">$i</span> = 0; <span class="variable">$i</span> &lt; <span class="variable">$length</span>; <span class="variable">$i</span>++ )  &#123;  </span><br><span class="line">            <span class="variable">$str</span> .= substr(<span class="variable">$chars</span>, mt_rand(0, strlen(<span class="variable">$chars</span>)-1), 1);  </span><br><span class="line">        &#125; </span><br><span class="line">        <span class="built_in">return</span> <span class="variable">$str</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 输出xml字符</span><br><span class="line">     * @throws WxPayException</span><br><span class="line">    **/</span><br><span class="line">    public  <span class="keyword">function</span> toXml(<span class="variable">$data</span>)&#123;</span><br><span class="line">        <span class="keyword">if</span>(!is_array(<span class="variable">$data</span>) || count(<span class="variable">$data</span>) &lt;= 0)&#123;</span><br><span class="line">            throw new WxPayException(<span class="string">&quot;数组数据异常！&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="variable">$xml</span> = <span class="string">&quot;&lt;xml&gt;&quot;</span>;</span><br><span class="line">        foreach (<span class="variable">$data</span> as <span class="variable">$key</span>=&gt;<span class="variable">$val</span>)&#123;</span><br><span class="line">            <span class="keyword">if</span> (is_numeric(<span class="variable">$val</span>))&#123;</span><br><span class="line">                <span class="variable">$xml</span>.=<span class="string">&quot;&lt;&quot;</span>.<span class="variable">$key</span>.<span class="string">&quot;&gt;&quot;</span>.<span class="variable">$val</span>.<span class="string">&quot;&lt;/&quot;</span>.<span class="variable">$key</span>.<span class="string">&quot;&gt;&quot;</span>;</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                <span class="variable">$xml</span>.=<span class="string">&quot;&lt;&quot;</span>.<span class="variable">$key</span>.<span class="string">&quot;&gt;&lt;![CDATA[&quot;</span>.<span class="variable">$val</span>.<span class="string">&quot;]]&gt;&lt;/&quot;</span>.<span class="variable">$key</span>.<span class="string">&quot;&gt;&quot;</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="variable">$xml</span>.=<span class="string">&quot;&lt;/xml&gt;&quot;</span>;</span><br><span class="line">        <span class="built_in">return</span> <span class="variable">$xml</span>; </span><br><span class="line">    &#125;</span><br><span class="line">	</span><br><span class="line">	 /**</span><br><span class="line">     * 以post方式提交xml到对应的接口url</span><br><span class="line">     *</span><br><span class="line">     * @param string <span class="variable">$xml</span>  需要post的xml数据</span><br><span class="line">     * @param string <span class="variable">$url</span>  url</span><br><span class="line">     * @param bool <span class="variable">$useCert</span> 是否需要证书，默认不需要</span><br><span class="line">     * @param int <span class="variable">$second</span>   url执行超时时间，默认30s</span><br><span class="line">     * @throws WxPayException</span><br><span class="line">     */</span><br><span class="line">    private <span class="keyword">function</span> postXmlCurl(<span class="variable">$xml</span>,<span class="variable">$url</span>,<span class="variable">$useCert</span> = <span class="literal">false</span>, <span class="variable">$second</span> = 30)&#123;</span><br><span class="line"></span><br><span class="line">        <span class="variable">$ch</span> = curl_init();</span><br><span class="line">        //设置超时</span><br><span class="line">        curl_setopt(<span class="variable">$ch</span>, CURLOPT_TIMEOUT, <span class="variable">$second</span>);</span><br><span class="line">        curl_setopt(<span class="variable">$ch</span>,CURLOPT_URL, <span class="variable">$url</span>);</span><br><span class="line">        curl_setopt(<span class="variable">$ch</span>,CURLOPT_SSL_VERIFYHOST,2);</span><br><span class="line">        //设置header</span><br><span class="line">        curl_setopt(<span class="variable">$ch</span>, CURLOPT_HEADER, FALSE);</span><br><span class="line">        //要求结果为字符串且输出到屏幕上</span><br><span class="line">        curl_setopt(<span class="variable">$ch</span>, CURLOPT_RETURNTRANSFER, TRUE);</span><br><span class="line">        <span class="keyword">if</span>(<span class="variable">$useCert</span> == <span class="literal">true</span>)&#123;</span><br><span class="line"></span><br><span class="line">            curl_setopt(<span class="variable">$ch</span>,CURLOPT_SSL_VERIFYPEER,1);</span><br><span class="line">            //设置证书</span><br><span class="line">            //使用证书：cert 与 key 分别属于两个.pem文件</span><br><span class="line">            curl_setopt(<span class="variable">$ch</span>,CURLOPT_SSLCERTTYPE,<span class="string">&#x27;PEM&#x27;</span>);               //证书的类型。支持的格式有<span class="string">&quot;PEM&quot;</span> (默认值), <span class="string">&quot;DER&quot;</span>和<span class="string">&quot;ENG&quot;</span>。</span><br><span class="line">            curl_setopt(<span class="variable">$ch</span>,CURLOPT_SSLCERT, <span class="variable">$this</span>-&gt;SSLCERT_PATH);   //一个包含PEM格式证书的文件名</span><br><span class="line">            curl_setopt(<span class="variable">$ch</span>,CURLOPT_SSLKEYTYPE,<span class="string">&#x27;PEM&#x27;</span>);               //私钥的加密类型，支持的密钥类型为<span class="string">&quot;PEM&quot;</span>(默认值)、<span class="string">&quot;DER&quot;</span>和<span class="string">&quot;ENG&quot;</span>。</span><br><span class="line">            curl_setopt(<span class="variable">$ch</span>,CURLOPT_SSLKEY, <span class="variable">$this</span>-&gt;SSLKEY_PATH);    //包含SSL私钥的文件名</span><br><span class="line">        &#125;<span class="keyword">else</span></span><br><span class="line">        &#123;</span><br><span class="line">            curl_setopt(<span class="variable">$ch</span>,CURLOPT_SSL_VERIFYPEER,FALSE);</span><br><span class="line">        &#125;</span><br><span class="line">        //post提交方式</span><br><span class="line">        curl_setopt(<span class="variable">$ch</span>, CURLOPT_POST, TRUE);</span><br><span class="line">        curl_setopt(<span class="variable">$ch</span>, CURLOPT_POSTFIELDS, <span class="variable">$xml</span>);</span><br><span class="line">        //运行curl</span><br><span class="line">        <span class="variable">$data</span> = curl_exec(<span class="variable">$ch</span>);</span><br><span class="line">        //var_dump(<span class="variable">$data</span>);die;</span><br><span class="line">        //返回结果</span><br><span class="line">        <span class="keyword">if</span>(<span class="variable">$data</span>)&#123;</span><br><span class="line">            curl_close(<span class="variable">$ch</span>);</span><br><span class="line">            <span class="built_in">return</span> <span class="variable">$data</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="variable">$error</span> = curl_errno(<span class="variable">$ch</span>);</span><br><span class="line">            curl_close(<span class="variable">$ch</span>);</span><br><span class="line">            throw new \Exception(<span class="string">&#x27;Sign faile&#x27;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">	 /**</span><br><span class="line">     * 将xml转为array</span><br><span class="line">     * @param string <span class="variable">$xml</span></span><br><span class="line">     * <span class="built_in">return</span> array</span><br><span class="line">     */</span><br><span class="line">    public <span class="keyword">function</span> xml_to_data(<span class="variable">$xml</span>)&#123;</span><br><span class="line">        <span class="keyword">if</span>(!<span class="variable">$xml</span>)&#123;</span><br><span class="line">            <span class="built_in">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        //将XML转为array</span><br><span class="line">        //禁止引用外部xml实体</span><br><span class="line">        libxml_disable_entity_loader(<span class="literal">true</span>);</span><br><span class="line">        <span class="variable">$data</span> = json_decode(json_encode(simplexml_load_string(<span class="variable">$xml</span>, <span class="string">&#x27;SimpleXMLElement&#x27;</span>, LIBXML_NOCDATA)), <span class="literal">true</span>);</span><br><span class="line">        <span class="built_in">return</span> <span class="variable">$data</span>;</span><br><span class="line">    &#125;</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">	</span><br><span class="line">    /**</span><br><span class="line">     * 支付回调验证</span><br><span class="line">     * @<span class="built_in">return</span> array 返回数组格式的notify数据</span><br><span class="line">     */</span><br><span class="line">    public   <span class="keyword">function</span> <span class="function"><span class="title">notify</span></span>()&#123;</span><br><span class="line">        // 获取xml</span><br><span class="line">        <span class="variable">$xml</span>=file_get_contents(<span class="string">&#x27;php://input&#x27;</span>, <span class="string">&#x27;r&#x27;</span>);</span><br><span class="line">        // 转成php数组</span><br><span class="line">        <span class="variable">$data</span>=<span class="variable">$this</span>-&gt;toArray(<span class="variable">$xml</span>);</span><br><span class="line">        paylog(<span class="string">&quot;回调返回结果:&quot;</span>.json_encode(<span class="variable">$data</span>));</span><br><span class="line">		//        <span class="variable">$res</span> = <span class="string">&#x27;&#123;&quot;appid&quot;:&quot;wx7beae0c50ca58a82&quot;,&quot;bank_type&quot;:&quot;CMB_CREDIT&quot;,&quot;cash_fee&quot;:&quot;1&quot;,&quot;fee_type&quot;:&quot;CNY&quot;,&quot;is_subscribe&quot;:&quot;N&quot;,&quot;mch_id&quot;:&quot;1601479852&quot;,&quot;nonce_str&quot;:&quot;qniwv0e8dg4fiirauwnz2oc88gc7ro6p&quot;,&quot;openid&quot;:&quot;o5QZu5Sx7qYFCYnGhCQBQpZZgfEE&quot;,&quot;out_trade_no&quot;:&quot;DD20200820110715820928352500527&quot;,&quot;result_code&quot;:&quot;SUCCESS&quot;,&quot;return_code&quot;:&quot;SUCCESS&quot;,&quot;sign&quot;:&quot;5967889244D408AADC91563B18500F99&quot;,&quot;time_end&quot;:&quot;20200820110721&quot;,&quot;total_fee&quot;:&quot;1&quot;,&quot;trade_type&quot;:&quot;JSAPI&quot;,&quot;transaction_id&quot;:&quot;4200000601202008209331044407&quot;&#125;&#x27;</span>;</span><br><span class="line">//        <span class="variable">$data</span> = json_decode(<span class="variable">$res</span>,<span class="literal">true</span>);</span><br><span class="line">        // 保存原sign</span><br><span class="line">        <span class="variable">$data_sign</span>=<span class="variable">$data</span>[<span class="string">&#x27;sign&#x27;</span>];</span><br><span class="line">        // sign不参与签名</span><br><span class="line">        <span class="built_in">unset</span>(<span class="variable">$data</span>[<span class="string">&#x27;sign&#x27;</span>]);</span><br><span class="line">        <span class="variable">$sign</span>=<span class="variable">$this</span>-&gt;makeSign(<span class="variable">$data</span>);</span><br><span class="line">        // 判断签名是否正确  判断支付状态</span><br><span class="line">        <span class="keyword">if</span> (<span class="variable">$sign</span>===<span class="variable">$data_sign</span> &amp;&amp; <span class="variable">$data</span>[<span class="string">&#x27;return_code&#x27;</span>]==<span class="string">&#x27;SUCCESS&#x27;</span> &amp;&amp; <span class="variable">$data</span>[<span class="string">&#x27;result_code&#x27;</span>]==<span class="string">&#x27;SUCCESS&#x27;</span>) &#123;</span><br><span class="line">            <span class="variable">$result</span>=<span class="variable">$data</span>;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="variable">$result</span>=<span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        // 返回状态给微信服务器</span><br><span class="line">        <span class="keyword">if</span> (<span class="variable">$result</span>) &#123;</span><br><span class="line">            <span class="variable">$str</span>=<span class="string">&#x27;&lt;xml&gt;&lt;return_code&gt;&lt;![CDATA[SUCCESS]]&gt;&lt;/return_code&gt;&lt;return_msg&gt;&lt;![CDATA[OK]]&gt;&lt;/return_msg&gt;&lt;/xml&gt;&#x27;</span>;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="variable">$str</span>=<span class="string">&#x27;&lt;xml&gt;&lt;return_code&gt;&lt;![CDATA[FAIL]]&gt;&lt;/return_code&gt;&lt;return_msg&gt;&lt;![CDATA[签名失败]]&gt;&lt;/return_msg&gt;&lt;/xml&gt;&#x27;</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">echo</span> <span class="variable">$str</span>;</span><br><span class="line">        <span class="built_in">return</span> <span class="variable">$result</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://huangxiaochang.gitee.io/ahuang_blog">Ahuang</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://huangxiaochang.gitee.io/ahuang_blog/2020/05/05/015/">http://huangxiaochang.gitee.io/ahuang_blog/2020/05/05/015/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://huangxiaochang.gitee.io/ahuang_blog" target="_blank">Ahuang'Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/ahuang_blog/tags/%E5%BE%AE%E4%BF%A1%E6%94%AF%E4%BB%98/">微信支付</a></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/ahuang_blog/2020/07/02/016/" title="微信App支付"><img class="cover" src="https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png" onerror="onerror=null;src='/ahuang_blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">微信App支付</div></div></a></div><div class="next-post pull-right"><a href="/ahuang_blog/2019/11/25/012/" title="第三方登录之微信登录"><img class="cover" src="https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png" onerror="onerror=null;src='/ahuang_blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">第三方登录之微信登录</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/ahuang_blog/2018/09/04/014/" title="微信支付（扫码付、公众号支付）"><img class="cover" src="https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2018-09-04</div><div class="title">微信支付（扫码付、公众号支付）</div></div></a></div><div><a href="/ahuang_blog/2020/07/02/016/" title="微信App支付"><img class="cover" src="https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-07-02</div><div class="title">微信App支付</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/ahuang_blog/img/Misaka.jpg" onerror="this.onerror=null;this.src='/ahuang_blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Ahuang</div><div class="author-info__description">Everything can be expected in the future</div></div><div class="card-info-data site-data is-center"><a href="/ahuang_blog/archives/"><div class="headline">文章</div><div class="length-num">51</div></a><a href="/ahuang_blog/tags/"><div class="headline">标签</div><div class="length-num">35</div></a><a href="/ahuang_blog/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/changad" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:136081905@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">快乐每一天！！！</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/ahuang_blog/2022/04/24/051/" title="项目中一些ThinkPhp的使用小技巧">项目中一些ThinkPhp的使用小技巧</a><time datetime="2022-04-24T10:43:22.000Z" title="发表于 2022-04-24 18:43:22">2022-04-24</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/ahuang_blog/2022/04/08/050/" title="Sql查询排名">Sql查询排名</a><time datetime="2022-04-08T08:24:16.000Z" title="发表于 2022-04-08 16:24:16">2022-04-08</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/ahuang_blog/2022/03/06/049/" title="ThinkPhp的跨域问题">ThinkPhp的跨域问题</a><time datetime="2022-03-06T04:40:38.000Z" title="发表于 2022-03-06 12:40:38">2022-03-06</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/ahuang_blog/2021/11/13/048/" title="Nginx关于Socket的配置">Nginx关于Socket的配置</a><time datetime="2021-11-13T07:02:15.000Z" title="发表于 2021-11-13 15:02:15">2021-11-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/ahuang_blog/2021/10/28/047/" title="Node.js之Express关于socket.io的使用">Node.js之Express关于socket.io的使用</a><time datetime="2021-10-28T04:36:17.000Z" title="发表于 2021-10-28 12:36:17">2021-10-28</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2018 - 2023 By Ahuang</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Everything can be expected in the future!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/ahuang_blog/js/utils.js"></script><script src="/ahuang_blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="/ahuang_blog/js/search/local-search.js"></script><div class="js-pjax"></div><script src="https://cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script><script async src="https://cdn.jsdelivr.net/npm/js-heo@1.0.11/categoryBar/categoryBar.js"></script><script src="/blog/js/categoryBar.js"><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = true;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>
  function butterfly_clock_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="/ahuang_blog/img/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_injector_config();
  }
  </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax src="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.js"></script><!-- hexo injector body_end end --></body></html>